<?php
require '../config.php';

$action = $_POST['action'];

$params = array(
        'appId'  => FB_APP_ID,
        'secret' => FB_APP_SECRET,
        'cookie' => true,
    );
$facebook_test = new FacebookTest($params);
$facebook_test->getAppAccessToken();

switch ($action) {
    case 'menu_create_user_test':
        $account = $facebook_test->createTestAccount();
        output($account);
        break;
    case 'menu_create_ten_user_test':
        $accounts = menu_create_ten_user_test($facebook_test);
        output($accounts);
        break;
        
    case 'menu_delete_all_users_test':
        $account = $facebook_test->deleteAllTestAccounts();
        output($account);
        break;        
    case 'menu_list_users_local':
        $accounts = $facebook_test->getPersistedTestAccounts();
        output($accounts);
        break;        
    case 'menu_list_users_app':
        $accounts = $facebook_test->getTestAccounts();
        output($accounts);
        break;    
    case 'menu_random_friends':
        menu_random_friends($facebook_test);
        output('se relacionaron las cuentas');
        break;        
    default:
        output('No existe la accion');	
    	break;
}


function menu_create_ten_user_test($facebook_test){
    for($i=0;$i<10;$i++){
        $accounts[]=$facebook_test->createTestAccount();
    }
    return $accounts;
}

function menu_random_friends($facebook_test){
    $accounts = $facebook_test->getTestAccounts();
    $count=count($accounts['data']);
    for($i=0;$i<$count-1;$i++){
        for($j=$i+1;$j<$count;$j++){
            $fbIdFrom=$accounts['data'][$i]['id'];
            $accessTokenFrom=$accounts['data'][$i]['access_token'];
            
            $fbIdTo=$accounts['data'][$j]['id'];
            $accessTokenTo=$accounts['data'][$j]['access_token'];
            
            $facebook_test->addFriends($fbIdFrom,$fbIdTo,$accessTokenFrom);
            $facebook_test->confirmFriends($fbIdFrom,$fbIdTo,$accessTokenTo);
            
        }
    }  
}
function output($msg){
    if(is_array($msg)){
        $msg = '<pre>'.print_r($msg,true).'</pre>';
    }
    
    echo "
    <a href='#' onclick='_wrapper.unblock();' >close</a>
    <div class='console_out'>$msg</div>
    ";      
}

 
        
